/**
 * WebWorker library
 * 
 * @author Rodrigo Longhi
 */
Workless = {

	/**
	 * Binds a callback to the workers response.
	 */
	bind: function(worker, callback) {
		worker.onmessage = callback;
	},

	/**
	 * Send data to the worker.
	 */
	post: function(worker, data) {
		worker.postMessage(data);
	},

	/**
	 * End worker lifetime.
	 */
	end: function(worker) {
		worker.terminate();
	},

	/**
	 * Create a new instance of WebWorker based on the code file specified.
	 */
	create: function(code) {
		var worker = new Worker(code);

		/*
		 * extend worker
		 */
		worker.bind = function(callback) {
			this.onmessage = callback;
		};

		worker.post = function(data) {
			this.postMessage(data);
		};

		return worker;
	}
};

// WebWorker validation
if (typeof (Worker) == 'undefined')
	alert('Unable to run WebWorker.');